﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Adams.Web.Areas.MyAdams.Logic.Classifieds
{
    public static class Create
    {
        public static MyAdams.Models.Classifieds.Create.PageLoad PageLoad(int memberid, int businessId)
        {
            return MyAdams.Data.Classifieds.Create.PageLoad(memberid, businessId);
        }

        public static Adams.Shared.Entities.Classifieds.CategoryCollection GetCategoriesByType(int typeId)
        {
            return MyAdams.Data.Classifieds.Create.GetCategoriesByType(typeId);
        }

        public static Adams.Web.Models.FormOutput Save(MyAdams.Models.Classifieds.Create.FormInput input)
        {
            var output = Adams.Web.Logic.Validation.PerformBasicValidation(input);

            if (output.IsValid)
            {
                var save = new MyAdams.Models.Classifieds.Create.SaveInput();
                Shared.ObjectHelper.CopyObject(input, ref save);

                save.Status = Shared.Entities.Classifieds.Status.PendingApproval;

                if (input.ID.ToInt() == 0)
                {
                    save.ExpiresOn = DateTime.Now.AddDays(14);
                }
                else
                {
                    save.ExpiresOn = DateTime.Now; //ignored
                }

                MyAdams.Data.Classifieds.Create.Save(save);
                output.IsSaved = true;
            }

            return output;
        }
    }
}